﻿<UserControl x:Class="Fluffy.Torrent.TorrentDocumentView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:torrent="clr-namespace:Fluffy.Torrent"
             xmlns:views="clr-namespace:Fluffy.Library.Views;assembly=Fluffy.Library"
             mc:Ignorable="d" d:DataContext="{d:DesignInstance torrent:TorrentDocumentViewModel}"
             d:DesignHeight="300" d:DesignWidth="600">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="300"/>
            <ColumnDefinition Width="5"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Grid Grid.Column="0" Margin="5">
            <Grid.Resources>
                <Style TargetType="TextBlock">
                    <Setter Property="Margin" Value="3"/>
                    <Setter Property="FontWeight" Value="Bold"/>
                </Style>
                <Style TargetType="TextBox">
                    <Setter Property="IsReadOnly" Value="True"/>
                    <Setter Property="BorderThickness" Value="0"/>
                    <Setter Property="Background" Value="Transparent"/>
                    <Setter Property="TextWrapping" Value="WrapWithOverflow"/>
                    <Setter Property="Margin" Value="3"/>
                </Style>
            </Grid.Resources>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <TextBlock Grid.Row="0" Grid.Column="0" Text="Name:"/>
            <TextBox Grid.Row="0" Grid.Column="1" Text="{Binding Name, Mode=OneTime}"/>
            <TextBlock Grid.Row="1" Grid.Column="0" Text="Comment:"/>
            <TextBox Grid.Row="1" Grid.Column="1" Text="{Binding Comment, Mode=OneTime}"/>
            <TextBlock Grid.Row="2" Grid.Column="0" Text="Created By:"/>
            <TextBox Grid.Row="2" Grid.Column="1" Text="{Binding CreatedBy, Mode=OneTime}"/>
            <TextBlock Grid.Row="3" Grid.Column="0" Text="Creation Date:"/>
            <TextBox Grid.Row="3" Grid.Column="1" Text="{Binding CreatedDate, Mode=OneTime}"/>
            <TextBlock Grid.Row="4" Grid.Column="0"  Text="Size:"/>
            <TextBox Grid.Row="4" Grid.Column="1"  Text="{Binding Size, Mode=OneTime}"/>
            <TextBlock Grid.Row="5" Grid.Column="0"  Text="Publisher:"/>
            <TextBox Grid.Row="5" Grid.Column="1"  Text="{Binding Publisher, Mode=OneTime}"/>
            <TextBlock Grid.Row="6" Grid.Column="0"  Text="PublisherUrl:"/>
            <TextBox Grid.Row="6" Grid.Column="1"  Text="{Binding PublisherUrl, Mode=OneTime}"/>
            <TextBlock Grid.Row="7" Grid.Column="0"  Text="Torrent Path:"/>
            <TextBox Grid.Row="7" Grid.Column="1"  Text="{Binding TorrentPath, Mode=OneTime}"/>
        </Grid>
        <GridSplitter Grid.Column="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
            <GridSplitter.Template>
                <ControlTemplate>
                    <Border Background="Transparent">
                        <Rectangle Width="1" Fill="#99CCCCCC" HorizontalAlignment="Center"/>
                    </Border>
                </ControlTemplate>
            </GridSplitter.Template>
        </GridSplitter>
        <DataGrid Grid.Column="2" ItemsSource="{Binding Files}" AutoGenerateColumns="False" SelectionMode="Extended" BorderThickness="0" GridLinesVisibility="None" IsReadOnly="True"
                  HeadersVisibility="Column" SelectionUnit="FullRow" Background="{x:Static SystemColors.WindowBrush}" EnableRowVirtualization="False" EnableColumnVirtualization="False">
            <DataGrid.Resources>
                <Style x:Key="ColumnHeaderGripperStyle" TargetType="{x:Type Thumb}">
                    <Setter Property="Width" Value="8" />
                    <Setter Property="Background" Value="Transparent" />
                    <Setter Property="Cursor" Value="SizeWE" />
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type Thumb}">
                                <Border Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}"/>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
                <Style TargetType="{x:Type DataGridColumnHeader}">
                    <Setter Property="VerticalContentAlignment" Value="Center" />
                    <Setter Property="Background" Value="Transparent" />
                    <Setter Property="Height" Value="24" />
                    <Setter Property="BorderThickness" Value="0,0,1,0" />
                    <Setter Property="VerticalAlignment" Value="Center" />
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type DataGridColumnHeader}">
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="*"/>
                                        <ColumnDefinition Width="Auto"/>
                                    </Grid.ColumnDefinitions>
                                    <Border Grid.ColumnSpan="2" Padding="3,0,3,0" Margin="0,0,-1,0" Background="{TemplateBinding Background}" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="#99CCCCCC" MinHeight="18" VerticalAlignment="{TemplateBinding VerticalAlignment}"/>
                                    <ContentPresenter Grid.Column="0" Margin="4,0" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
                                    <Thumb Grid.Column="0" Grid.ColumnSpan="2" x:Name="PART_LeftHeaderGripper" HorizontalAlignment="Left" Style="{StaticResource ColumnHeaderGripperStyle}" />
                                    <Thumb Grid.Column="0" Grid.ColumnSpan="2" x:Name="PART_RightHeaderGripper" HorizontalAlignment="Right" Style="{StaticResource ColumnHeaderGripperStyle}" />
                                    <Path Grid.Column="1" x:Name="SortArrow" Visibility="Hidden" Data="M0,0 L1,0 0.5,1 z" Stretch="Fill" 
                                        HorizontalAlignment="Right" Width="8" Height="6" Stroke="DarkGray" Fill="LightGray" Margin="8,0" 
                                        VerticalAlignment="Center" RenderTransformOrigin="0.5,0.4" />
                                </Grid>
                                <ControlTemplate.Triggers>
                                    <Trigger Property="SortDirection" Value="Ascending">
                                        <Setter TargetName="SortArrow" Property="Visibility" Value="Visible" />
                                        <Setter TargetName="SortArrow" Property="RenderTransform">
                                            <Setter.Value>
                                                <RotateTransform Angle="180" />
                                            </Setter.Value>
                                        </Setter>
                                    </Trigger>
                                    <Trigger Property="SortDirection" Value="Descending">
                                        <Setter TargetName="SortArrow" Property="Visibility" Value="Visible" />
                                    </Trigger>
                                </ControlTemplate.Triggers>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                    <Style.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="Background" Value="#FFFAFAFA"/>
                            <Setter Property="BorderThickness" Value="1"/>
                            <Setter Property="VerticalAlignment" Value="Stretch" />
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </DataGrid.Resources>
            <DataGrid.RowStyle>
                <Style TargetType="Control">
                    <Setter Property="Margin" Value="0,1"/>
                </Style>
            </DataGrid.RowStyle>
            <DataGrid.CellStyle>
                <Style TargetType="{x:Type DataGridCell}" BasedOn="{StaticResource {x:Type DataGridCell}}">
                    <Setter Property="BorderThickness" Value="0"/>
                </Style>
            </DataGrid.CellStyle>
            <DataGrid.Columns>
                <DataGridTemplateColumn Header="Name" Width="300" SortMemberPath="Name">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <StackPanel Margin="3,0,0,0" Orientation="Horizontal" d:DataContext="{d:DesignInstance torrent:TorrentFileViewModel}">
                                <Image Source="{Binding Icon}"/>
                                <TextBlock Text="{Binding Name}" Margin="5,0,0,0"/>
                            </StackPanel>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
                <DataGridTextColumn Header="Path" Binding="{Binding Path}" />
                <DataGridTextColumn Header="Size" Binding="{Binding SizeTitle}" SortMemberPath="Size">
                    <DataGridTextColumn.CellStyle>
                        <Style TargetType="{x:Type DataGridCell}" BasedOn="{StaticResource {x:Type DataGridCell}}">
                            <Setter Property="Block.TextAlignment" Value="Right"/>
                            <Setter Property="BorderThickness" Value="0"/>
                        </Style>
                    </DataGridTextColumn.CellStyle>
                </DataGridTextColumn>
                <DataGridTextColumn Header="Priority" Binding="{Binding PriorityTitle}" SortMemberPath="Priority"/>
            </DataGrid.Columns>
            <DataGrid.ContextMenu>
                <ContextMenu>
                    <MenuItem Header="Start" Command="{Binding StartCommand}"/>
                    <Separator/>
                    <MenuItem Header="Priority">
                        <MenuItem Header="Do Not Download" Command="{Binding SetDoNotDownloadPriorityCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ContextMenu}}, Path=PlacementTarget.SelectedItems}"/>
                        <MenuItem Header="Lowest" Command="{Binding SetLowestPriorityCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ContextMenu}}, Path=PlacementTarget.SelectedItems}"/>
                        <MenuItem Header="Low" Command="{Binding SetLowPriorityCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ContextMenu}}, Path=PlacementTarget.SelectedItems}"/>
                        <MenuItem Header="Normal" Command="{Binding SetNormalPriorityCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ContextMenu}}, Path=PlacementTarget.SelectedItems}"/>
                        <MenuItem Header="High" Command="{Binding SetHighPriorityCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ContextMenu}}, Path=PlacementTarget.SelectedItems}"/>
                        <MenuItem Header="Highest" Command="{Binding SetHighestPriorityCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ContextMenu}}, Path=PlacementTarget.SelectedItems}"/>
                        <MenuItem Header="Immediate" Command="{Binding SetImmediatePriorityCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ContextMenu}}, Path=PlacementTarget.SelectedItems}"/>
                    </MenuItem>
                </ContextMenu>
            </DataGrid.ContextMenu>
        </DataGrid>
        <views:WaitView Grid.ColumnSpan="3" DataContext="{Binding}"/>
    </Grid>
</UserControl>
